package com.mini.mybatis.type;

import java.sql.Types;

/**
 * JDBC类型枚举
 * 对应java.sql.Types中的常量
 */
public enum JdbcType {
    
    // 常用的JDBC类型
    INTEGER(Types.INTEGER),
    BIGINT(Types.BIGINT),
    SMALLINT(Types.SMALLINT),
    TINYINT(Types.TINYINT),
    
    VARCHAR(Types.VARCHAR),
    CHAR(Types.CHAR),
    LONGVARCHAR(Types.LONGVARCHAR),
    
    DECIMAL(Types.DECIMAL),
    NUMERIC(Types.NUMERIC),
    REAL(Types.REAL),
    FLOAT(Types.FLOAT),
    DOUBLE(Types.DOUBLE),
    
    BIT(Types.BIT),
    BOOLEAN(Types.BOOLEAN),
    
    DATE(Types.DATE),
    TIME(Types.TIME),
    TIMESTAMP(Types.TIMESTAMP),
    
    BLOB(Types.BLOB),
    CLOB(Types.CLOB),
    
    NULL(Types.NULL),
    OTHER(Types.OTHER);
    
    public final int TYPE_CODE;
    
    JdbcType(int code) {
        this.TYPE_CODE = code;
    }
    
    /**
     * 根据类型代码获取JdbcType
     * @param code 类型代码
     * @return JdbcType枚举值
     */
    public static JdbcType forCode(int code) {
        for (JdbcType type : JdbcType.values()) {
            if (type.TYPE_CODE == code) {
                return type;
            }
        }
        return null;
    }
}